package com.opennice.soukaoti.paper.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.opennice.soukaoti.dao.BaseDAO;
import com.opennice.soukaoti.paper.dao.IPAnswerDAO;
import com.opennice.soukaoti.vo.LearngoUser;
import com.opennice.soukaoti.vo.PAnswer;

public class PAnswerDAO extends BaseDAO implements IPAnswerDAO {

	@Override
	public void deleteAnswer(int paid) {
		
	}
	@Override
	public ArrayList<PAnswer> getAnswersAsPtitle(int ptId) {
		Session session = getSession();
		Transaction tx = session.beginTransaction();
		String hql = "from PAnswer as m where m.ptId=:ptId";
		Query query = session.createQuery(hql);
		query.setInteger("ptId", ptId);
		List<PAnswer> list = query.list();
		tx.commit();
		session.close();
		return (ArrayList<PAnswer>) list;
	}
	@Override
	public PAnswer loadAnswer(int paid) {
		Session session = getSession();
		Transaction tx = session.beginTransaction();
		PAnswer pAnswer = (PAnswer) session.load(PAnswer.class, paid);
		tx.commit();
		session.close();
		return pAnswer;
	}

	@Override
	public void saveAnswer(PAnswer answer) {
		// TODO Auto-generated method stub
		Session session = getSession();
		Transaction tx = session.beginTransaction();
		session.save(answer);
		tx.commit();
		session.close();
	}
	@Override
	public void updateAnswer(PAnswer answer) {
		Session session = getSession();
		Transaction tx = session.beginTransaction();
		session.update(answer);
		tx.commit();
		session.close();
	}
}
